<?php
class CodeSpace_Oauth_Server_Request_Service extends CodeSpace_Oauth_Server_Request_Abstract
{
    public function __construct ($options = null)
    {
        parent::__construct($options);
    }
    
    public function buildControlSignature($config)
    {
        $params = array ();
        $params['oauth_consumer_key'] = $config->getConsumer()->getKey();
        $params['oauth_nonce'] = $config->getNonce();
        $params['oauth_signature_method'] = $config->getSignatureMethod();
        $params['oauth_timestamp'] = $config->getTimestamp();
        $params['oauth_token'] = $config->getToken()->getToken();
        $params['oauth_version'] = $config->getVersion();
        $params = array_merge($params, $config->getUserParams());
        
        $utility = new Zend_Oauth_Http_Utility;
        $sign = $utility->sign(
            $params,
            $config->getSignatureMethod(),
            $config->getConsumer()->getSecret(),
            'access_token_secret',
            'POST',
            'http://morpheus.gateway.mkb.com:41000/service'
        );
        
        return $sign;
    }
    
    private function _checkServiceIdentification()
    {
        $userParams = $this->_oauthServer->getUserParams();
        $serviceIdentity = $userParams['service_identity'];
        
        $serviceTable = new Model_DbTable_Services();
        $resultSet = $serviceTable->find($serviceIdentity);
        
        if($resultSet->count() == 0)
        {
            throw new Exception('Invalid Service Request');
        }
        if($resultSet->count() > 1)
        {
            throw new Exception('Confusing Service Request');
        }
    }
    
    private function _checkConsumerAgainstService()
    {
        $consumerKey = $this->_oauthServer->getConsumerKey();
        $userParams = $this->_oauthServer->getUserParams();
        $serviceIdentification = $userParams['service_identity'];
        $serviceType = $userParams['service_type'];
        
        $conSerXref = new Model_DbTable_ConsumerServicesXref();
        $resultSet = $conSerXref->find($consumerKey, $serviceIdentification, $serviceType);
        
        if($resultSet->count() == 0 || $resultSet->count() > 1)
        {
            throw new Exception('Permission Denied');
        }
    }
    
    public function process(CodeSpace_Oauth_Server $server)
    {
        
    }
}
?>